package com.tcoiss.job.jobhandler.base;

import com.tcoiss.common.core.domain.R;
import com.tcoiss.common.component.api.RemoteDataFactoryService;
import com.tcoiss.common.component.api.model.SchemeVO;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
public class CommonJob {
    @Autowired
    private RemoteDataFactoryService remoteDataFactoryService;

    protected ReturnT<String> commonJobHandler(String jobParam){
        XxlJobLogger.log("开始执行方案");
        //更据任务编码调用数据工厂接口执行方案，执行同步逻辑
        SchemeVO vo = new SchemeVO();
        vo.setExecuteNumber(jobParam);
        vo.setExecuteType(1);
        R<Boolean> result = remoteDataFactoryService.executeScheme(vo);
        if(result==null){
            return new ReturnT(500,"同步数据时访问数据工厂服务异常,任务参数为："+jobParam);
        }
        if(result.getCode() == 200){
            XxlJobLogger.log("同步数据时成功！任务参数为："+jobParam);
            return ReturnT.SUCCESS;
        }else{
            XxlJobLogger.log("同步数据时失败！任务参数为："+jobParam);
            return new ReturnT(500,"同步数据时失败！程序异常："+result.getMsg()+", 任务参数为："+jobParam);
        }
    }



}
